package com.s7_compat.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.s7.compat.network.exception.ResponeThrowable;
import com.s7.compat.network.listener.OnRequestListener;
import com.s7_compat.R;
import com.s7_compat.net.APIManager;
import com.s7_compat.net.HttpData;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HttpActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn1;
    private TextView hint;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_http);

        btn1 = findViewById(R.id.http_btn_1);
        hint = findViewById(R.id.http_hint);

        btn1.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.http_btn_1:
                onHttp();
                break;
        }
    }

    private void onHttp() {
        Map<String, String> h = new HashMap<>();
//        h.put("timestamp","1587975265");
//        h.put("platform","1");
//        h.put("version","1.4.0");
//        h.put("uid","5813994");
//        h.put("deviceID","918fb8f8-bc57-3962-b523-0ac2c89ecc1c");
//        h.put("uuid","865166021906444");
//        h.put("sign","df89e2e55d1f5654a9feb5c7e55effd7");
//        h.put("appid","1");
//        h.put("token","67f8fd8c9da52f686fc23bda7de840e4");
//        h.put("Content-Type","application/x-www-form-urlencoded");
//        h.put("Content-Length","63");
//        h.put("Host","sbfc912z.com");
//        h.put("Connection","Keep-Alive");
//        h.put("Accept-Encoding","gzip");
//        h.put("User-Agent","okhttp/3.10.0");
//        h.put("Host","sbfc912z.com");

        Map<String, String> p = new HashMap<>();
        p.put("pathParams","key");
        p.put("bodyParams","我");
        APIManager.getInstance().toSubscribe(APIManager.getInstance().onPost(h, p),
                new OnRequestListener<Object>() {
//                    @Override
//                    public void onSuccess(List<HttpData> data) {
//                        if (data != null && data.size() > 0) {
//                            Log.d("解析结果", data.get(0).getAir_level());
//                            hint.setText(data.get(0).getWea());
//                        }
//                        Log.d("解析结果", "为空");
//                        hint.setText("为空");
//                    }

                    @Override
                    public void onSuccess(Object data) {

                    }

                    @Override
                    public void onError(ResponeThrowable error) {
                        Log.d("请求错误", error.message);
                    }
                });
    }
}
